#ifndef __ADU_GAME_PLAY_SCENE_H__
#define __ADU_GAME_PLAY_SCENE_H__

#include "cocos2d.h"
#include "ADUConstant.h"
#include "ADUWater.h"
#include "ADUPipe.h"
#include "ADUConfig.h"
#include "ADUBasin.h"
#include "ADUDuck.h"
#include "ADUEatable.h"
#include "GLES-Render.h"
#include "ADUGameOverScene.h"
#include <Box2D/Box2D.h>
#include "extensions/cocos-ext.h"
#include "ui/CocosGUI.h"

USING_NS_CC_EXT;
using namespace ui;

class Flow;
class Basin;
class Duck;
class FollowLayer;
class GameOverLayer;
class Eatable;

USING_NS_CC;
using namespace std;

class GamePlayLayer : public cocos2d::Layer
{
public:
    static cocos2d::Scene* createScene();
    virtual bool init();  
    void update(float dt);
	void OnExitClicked();
	void OnPauseClicked();
	void OnSoundClicked();
	void OnMusicClicked();
    CREATE_FUNC(GamePlayLayer);

	virtual bool onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event);
	virtual void onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *event);
	virtual void onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event);
	virtual void onTouchCancelled(cocos2d::Touch *touch, cocos2d::Event *event);

	void setTouchEnabled(bool enabled);
	Water* getWater() {return mWater;};
	void showGameOverPopUp();
	void touchMusic(Ref *pSender, Widget::TouchEventType type);
	void touchExit(Ref *pSender, Widget::TouchEventType type);
	void touchPause(Ref *pSender, Widget::TouchEventType type);
	void touchSound(Ref *pSender, Widget::TouchEventType type);
	void showTutorial();
    float getTopBackgroundHeight();
    void createWall();
    
    void ShowSpeedUpText();
    void ShowSpeedUpTextDone();
	
private:
	EventListenerTouchOneByOne* mTouchListener;
	Sprite*						mTopBackground;
    Water* 						mWater;
	Pipe*						mPipe;
	float 						mt;
	Button* 					mExitButton;
	Button* 					mPauseButton;
	Button* 					mSoundButton;
	Button* 					mMusicButton;
	Flow*						mFlow;
	b2World* 					mWorld;
	bool						mAllowFlow;
	bool						mPaused;
	Text*						mLabelScore;
    Text*						mSpeedUpText;
	GameOverLayer*				mGameOverLayer;
	bool						isMusicPlaying;
    static FollowLayer          *mFllowLayer;
    bool                        gameOver;
    Sprite* 					mHand;
    b2Body                      *mGroundBody;
    int                         playedTime;
    float                       miliSecCount;
};


class FollowLayer : public cocos2d::Layer
{
public:
	static FollowLayer* create(GamePlayLayer*);
	FollowLayer(GamePlayLayer* layer);
	FollowLayer(){};
	~FollowLayer();
	virtual bool init();        
	CREATE_FUNC(FollowLayer);
	void addDuckWithCoords(Vec2 p);
	void AddGarbage();
	void addBasinWithCoords(Vec2 p, int num);
	virtual void draw(Renderer *renderer, const Mat4& transform, uint32_t flags);
	void update(float dt);
	void follow(Node* follower, Node* target);
    void UpdateScore();
    int GetDuckHealth();

    void UpdateBasin();
    
    void UpdateEatables();

private:
	b2World*                    mWorld;
	SpriteBatchNode*            mSprBatchNode ;
	Duck*                       mSprDuck;
	Sprite*                     mSprBasin;
	Water*                      mWater;
    Basin**                     mBasin;
    GamePlayLayer               *mPlayLayer;
    
    Eatable                     *mFish;
};

#endif // __HELLOWORLD_SCENE_H__

